package com.shengqi.xinnongren.work.ui.goods.presenter;

import com.shengqi.xinnongren.common.base.BasePresenter;
import com.shengqi.xinnongren.common.config.network.Constants;
import com.shengqi.xinnongren.common.config.network.RetrofitHelper;
import com.shengqi.xinnongren.common.config.user.UserManager;
import com.shengqi.xinnongren.work.ui.goods.view.BrowseCommentView;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class BrowseCommentPresenter extends BasePresenter<BrowseCommentView> {
    /**
     * 获取商品详情
     */
    public void getGoodsDetails(String goodsId, int type,int page) {
        Map<String, Object> data = new HashMap<>();
        data.put("comId", goodsId);
        data.put("type", type);
        data.put("start", page);
        data.put("size", 10);
        final JSONObject jsonData = Constants.getJsonData(data, UserManager.getInstance().getToken());
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonData.toString());
        addTask(RetrofitHelper.getInstance().getService().getGoodsCommentList(requestBody), listHttpRespond -> {
            if (listHttpRespond.result == 1) {
                getView().onGetCommentListSucceed(listHttpRespond.data);
            }
        });
    }
}
